import { Request, Response, NextFunction } from 'express'
import { signToken } from './auth.service'

export const login = async (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  const { id, name } = req.body

  const payload = { id, name }

  try {
    const token = signToken({ payload })

    res.send({ token })
  } catch (error) {
    next(error)
  }
}
